home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Especial Multimedia
/
Especial Multimedia.iso
/
Multimed
/
Prg
/
KALENDAR.ZIP
/
KALENDAR.BAS
< prev
next >
Wrap
BASIC Source File
|
1997-09-14
|
9KB
|
237 lines
Option Explicit
' Drawing states for Kalendar_DrawDay
Global Const KAL_STATE_NOT_SELECTED = 0 ' Day not selected
Global Const KAL_STATE_SELECTED_WITH = 1 ' Day selected, Kalendar has focus
Global Const KAL_STATE_SELECTED_WITHOUT = 2 ' Day selected, Kalendar does not have focus
Global Const KAL_STATE_OTHERMONTH = 3 ' Day is not from this month.
' Kalendar printing options
Global Const KAL_PRINT_PORTRAIT = 1 ' Print Kalendar full page in portrait mode.
Global Const KAL_PRINT_LANDSCAPE = 2 ' Print Kalendar landscape full page
Global Const KAL_PRINT_USER = 3 ' Print Kalendar as specified by user.
' KalendarDrawBitmap bitmap alignments
Global Const KAL_DBM_UL = 0 ' Draw bitmap in upper left of daybox.
Global Const KAL_DBM_UC = 1 ' Draw bitmap in upper center of daybox.
Global Const KAL_DBM_UR = 2 ' Draw bitmap in upper right of daybox.
Global Const KAL_DBM_CL = 3 ' Draw bitmap in center left of daybox.
Global Const KAL_DBM_CC = 4 ' Draw bitmap in center center of daybox.
Global Const KAL_DBM_CR = 5 ' Draw bitmap in center right of daybox.
Global Const KAL_DBM_LL = 6 ' Draw bitmap in lower left of daybox.
Global Const KAL_DBM_LC = 7 ' Draw bitmap in lower center of daybox.
Global Const KAL_DBM_LR = 8 ' Draw bitmap in lower right of daybox.
' KalDrawBitmap
'
' Draws a bitmap from a picture control onto a day box.
'
' Parameters:
' hdc - hdc to draw on (usu. from DrawDay or DrawOnDay parameter)
' Pict - picture control that contains the bitmap the draw.
' NOTES: Pict.AutoDraw must be true.
' The size of the control should match the size of the bitmap (set Pict.AutoSize to true)
' You may want to turn off the border.
' x, y, x2, y2 - The size of the day box ( from DrawDay or DrawOnDay parameters)
' Position - One of the KAL_DBM_ constants
' dwROp - Bitwise operation to use to draw the bitmap. See the SRC constants in the
' Win31API.Txt file, provided with VB, for the various values.
Sub KalDrawBitmap (hDC As Integer, Pict As Control, x As Single, y As Single, x2 As Single, y2 As Single, Position As Integer, dwROp As Long)
Dim retval As Integer
Dim R As Rect
Dim W As Long, H As Long
Dim pixPictWidth As Integer
Dim pixPictHeight As Integer
KalWindowAPIRect x, y, x2, y2, R
InflateRect R, -1, -1
' Save the pictures height and width as pixels
pixPictWidth = Pict.Width / Screen.TwipsPerPixelY
pixPictHeight = Pict.Height / Screen.TwipsPerPixelY
Select Case Position
Case 0 ' Upper left
Case 1 ' Upper center
R.left = R.left + ((R.right - R.left + 1) - pixPictWidth) / 2
Case 2 ' Upper right
R.left = R.right - pixPictWidth + 1
Case 3 ' Center left
R.top = R.top + ((R.bottom - R.top + 1) - pixPictHeight) / 2
Case 4 ' Center center
R.left = R.left + ((R.right - R.left + 1) - pixPictWidth) / 2
R.top = R.top + ((R.bottom - R.top + 1) - pixPictHeight) / 2
Case 5 ' Center right
R.top = R.top + ((R.bottom - R.top + 1) - pixPictHeight) / 2
R.left = R.right - pixPictWidth + 1
Case 6 ' Lower left
R.top = R.bottom - pixPictHeight + 1
Case 7 ' Lower center
R.top = R.bottom - pixPictHeight + 1
R.left = R.left + ((R.right - R.left + 1) - pixPictWidth) / 2
Case 8 ' Lower right
R.top = R.bottom - pixPictHeight + 1
R.left = R.right - pixPictWidth + 1
End Select
W = pixPictWidth
If W > R.right - R.left + 1 Then
W = R.right - R.left + 1
End If
H = pixPictHeight
If H > R.bottom - R.top + 1 Then
H = R.bottom - R.top + 1
End If
retval = BitBlt(hDC, R.left, R.top, W, H, Pict.hDC, 0, 0, dwROp)
End Sub
' KalDrawDay
'
' Sample code to draw the entire day box. It only draws the day number in the upper left corner
' of the day box.
'
' Parameters:
' Kal - The Kalendar being drawn on
' hDC - hDC from the DrawDay or DrawOnDay call.
' State - the State from the DrawDay or DrawOn Day call
' theDay - theDay from the DrawDay or DrawOn Day call
' x, y, x2, y2 - coordinate parameters form the DrawDay or DrawOnDay call
Sub KalDrawDay (Kal As Control, hDC As Integer, STATE As Integer, theDay As Long, x As Single, y As Single, x2 As Single, y2 As Single)
Dim tmpx As Integer
Dim oldPen As Integer
Dim txtDay As String
Dim R As Rect
Dim oldBrush
Dim oldColor, oldTextColor
Dim lx As Long
Dim StrTmp As String
Dim linePen As Integer
Dim OldFont As Integer, theFont As Integer
txtDay = Format(theDay, "d")
KalWindowAPIRect x, y, x2, y2, R
linePen = CreatePen(PS_SOLID, 1, Kal.LineColor)
theFont = KalMakeFont(hDC, Kal)
oldPen = SelectObject(hDC, linePen)
OldFont = SelectObject(hDC, theFont)
Select Case STATE
Case KAL_STATE_SELECTED_WITHOUT
oldBrush = SelectObject(hDC, GetStockObject(LTGRAY_BRUSH))
oldColor = SetBkColor(hDC, RGB(192, 192, 192))
oldTextColor = SetTextColor(hDC, 0)
Case KAL_STATE_SELECTED_WITH
oldBrush = SelectObject(hDC, GetStockObject(LTGRAY_BRUSH))
oldColor = SetBkColor(hDC, RGB(192, 192, 192))
oldTextColor = SetTextColor(hDC, RGB(255, 0, 0))
Case KAL_STATE_NOT_SELECTED
oldBrush = SelectObject(hDC, GetStockObject(WHITE_BRUSH))
oldColor = SetBkColor(hDC, RGB(255, 255, 255))
oldTextColor = SetTextColor(hDC, 0)
Case KAL_STATE_OTHERMONTH
oldBrush = SelectObject(hDC, GetStockObject(LTGRAY_BRUSH))
oldColor = SetBkColor(hDC, RGB(192, 192, 192))
oldTextColor = SetTextColor(hDC, RGB(255, 255, 255))
End Select
tmpX = Rectangle(hDC, R.left, R.top, R.right, R.bottom)
' Draw the day number
InflateRect R, -1, -1
tmpX = DrawText(hDC, txtDay, Len(txtDay), R, DT_LEFT Or DT_SINGLELINE)
tmpX = SelectObject(hDC, oldPen)
tmpX = SelectObject(hDC, OldFont)
tmpX = DeleteObject(linePen)
tmpX = DeleteObject(theFont)
tmpX = SelectObject(hDC, oldBrush)
lx = SetBkColor(hDC, oldColor)
lx = SetTextColor(hDC, oldTextColor)
End Sub
' KalDrawText
'
' Draws text in a day box.
'
' Parameters:
' hdc - hdc from DrawDay or DrawOnDay call.
' theDay - theDay from DrawDay or DrawOnDay call.
' R - the rectangle in which the text will be drawn.
' txt$ - the string to be drawn
' ctlFont - a control that is set up with the font and forecolor that the text is to be drawn in.
' MultiLine - True to draw text with word-wrap.
Sub KalDrawText (hDC As Integer, theDay As Long, R As Rect, ByVal txt$, ctlFont As Control, MultiLine As Integer)
Dim retval As Integer
Dim oldTextColor As Long
Dim lx As Long
Dim oldBkMode As Integer
Dim OldFont As Integer
Dim HFont As Integer
If Len(txt) > 0 Then
'--- Set up the drawing information
oldBkMode = setBkMode(hDC, TRANSPARENT)
oldTextColor = SetTextColor(hDC, ctlFont.ForeColor)
HFont = KalMakeFont(hDC, ctlFont)
OldFont = SelectObject(hDC, HFont)
retval = DrawText(hDC, txt, Len(txt), R, DT_LEFT Or IIf(MultiLine, DT_WORDBREAK, 0))
' Clean up after myself.
retval = SelectObject(hDC, OldFont)
retval = DeleteObject(HFont)
'--- Restore the old drawing information
oldBkMode = setBkMode(hDC, oldBkMode)
lx = SetTextColor(hDC, oldTextColor)
End If
End Sub
' KalMakeFont
'
' This function creates a font that is described by the font properties of a control.
'
' Parameters:
' hDC - hdc parameter from DrawDay or DrawOnDay
' Ctl - the control that has the font information
Function KalMakeFont (hDC As Integer, Ctl As Control) As Integer
Dim FWBold As Integer
If Ctl.FontBold Then
FWBold = FW_BOLD
Else
FWBold = FW_NORMAL
End If
KalMakeFont = CreateFont(-(Ctl.FontSize * GetDeviceCaps(hDC, LOGPIXELSY) / 72), 0, 0, 0, FWBold, Ctl.FontItalic, Ctl.FontUnderline, Ctl.FontStrikethru, 0, 0, 0, 0, DEFAULT_PITCH Or FF_DONTCARE, Ctl.FontName)
End Function
' KalWindowAPIRect
'
' Converts rectangular twip coordinates into a Windows API Rectangle Structure
'
' Parameters
' x, y, x2, y2 - parameters from the DrawDay or DrawOnDay call.
' rct - rectangle structure to hold converted coordinates.
Sub KalWindowAPIRect (x As Single, y As Single, x2 As Single, y2 As Single, rct As Rect)
rct.left = x / Screen.TwipsPerPixelX
rct.top = y / Screen.TwipsPerPixelY
rct.right = x2 / Screen.TwipsPerPixelX
rct.bottom = y2 / Screen.TwipsPerPixelY
End Sub